#include <interfacelib/window/baloonbox.h>

using namespace interfacelib::Window;

BaloonBox::BaloonBox() : m_topImage( NULL ), m_bottomImage( NULL )
{
}

BaloonBox::~BaloonBox()
{
//	SAFE_DELETE( m_topImage );
//	SAFE_DELETE( m_bottomImage );
}

bool BaloonBox::create( const char *topImage, const char *lineImage, const char *bottomImage, int x, int y, DWORD attribute )
{
	{
		m_topImage = new interfacelib::Window::Window;

		m_topImage->create( topImage, 0, 0, interfacelib::Window::Window::VISIBLE | interfacelib::Window::Window::DISABLEINPUT );


		add( m_topImage );
	}
	{
		m_textWindow = new interfacelib::Window::EditBox;

		m_textWindow->create( lineImage, 0, m_topImage->getHeight(), interfacelib::Window::Window::VISIBLE | interfacelib::Window::Window::DISABLEINPUT );

		m_textWindow->setStartX( 2 );
		m_textWindow->setRightGap( 2 );
		m_textWindow->setWordWrap( true );
		m_textWindow->setReadOnly( true );
		m_textWindow->setMultiLine( true );
		m_textWindow->setFormat( DT_CENTER );

		add( m_textWindow );
	}
	{
		m_bottomImage = new interfacelib::Window::Window;

		m_bottomImage->create( bottomImage, 0, m_topImage->getHeight() + m_textWindow->getHeight() , interfacelib::Window::Window::VISIBLE | interfacelib::Window::Window::DISABLEINPUT  );

		add( m_bottomImage );
	}	

	bool result = Panel::create( NULL , x, y, attribute );
	setWindowPos( x, y, m_topImage->getWidth(), m_topImage->getHeight() + m_textWindow->getHeight() + m_bottomImage->getHeight() );

	return ( result );
}

void BaloonBox::setString( const char *string )
{
	m_textWindow->clear();

	m_textWindow->setString( string );

	SIZE totalLineSize = { 0 , 0 };
	POINT pt = { 0 , 0 };
	getWindowPos( &pt );
	m_textWindow->getTotalLineSize( &totalLineSize );
	setWindowPos( pt.x,pt.y, m_topImage->getWidth(), m_topImage->getHeight() + totalLineSize.cy + m_bottomImage->getHeight() );

	m_textWindow->setWindowPos( 0, m_topImage->getHeight(), m_topImage->getWidth(), totalLineSize.cy );
	m_textWindow->setTopLine();

	m_bottomImage->setWindowPos( 0, m_topImage->getHeight() + m_textWindow->getHeight() );

}


void BaloonBox::draw( Window *checkWindow )
{
	Panel::draw( checkWindow );
}

void BaloonBox::setColor( DWORD fore )
{
	m_textWindow->setForeGroundColor( fore );
}


void BaloonBox::setColor( DWORD fore, DWORD back )
{
	m_textWindow->setStyle( fore, back );
}